package com.manage.platform.controller;


import com.manage.platform.dto.*;
import com.manage.platform.service.impl.OrganizeServiceImpl;
import com.manage.platform.service.impl.TaskServiceImpl;
import com.manage.platform.service.impl.UserServiceImpl;
import com.manage.platform.utils.R;
import com.manage.platform.vo.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lk  注：此模块为学院类型的任务
 */
@AllArgsConstructor
@RestController
@RequestMapping("/taskList")
@Tag(name = "建设任务-建设进度")
public class TaskListController {

    private final TaskServiceImpl taskServiceImpl;
    private final OrganizeServiceImpl organizeServiceImpl;
    private final UserServiceImpl userServiceImpl;

    //查询学院列表(一级学院)
    @GetMapping("/getCollegeListPart")
    @Operation(summary = "1.学院列表(一级学院)")
    public R<List<CommonVo>> getCollegeListPart() {
        List<CommonVo> list = new ArrayList<>();
        // 添加"全部"选项
        CommonVo allOption = new CommonVo();
        allOption.setId(-1L);
        allOption.setName("全部");
        list.add(allOption);
        List<CommonVo> collegeNames = organizeServiceImpl.getCollegeListPart();
        for (int i = 0; i < collegeNames.size(); i++) {
            CommonVo collegeVo = new CommonVo();
            collegeVo.setId((long) i); // 生成ID，从1开始
            collegeVo.setName(collegeNames.get(i).getName());
            list.add(collegeVo);
        }
        return R.ok(list);
    }

    //任务数据统计
    @GetMapping("/statistics")
    @Operation(summary = "2.任务数据统计")
    public R<TaskStatisticsVo> statistics(@Schema(description = "学院ID")
                                          @RequestParam(value = "organizeId", required = false) Long organizeId) {
        return R.ok(taskServiceImpl.statistics(organizeId));
    }

    @GetMapping("/getAnnualList")
    @Operation(summary = "3.年度列表")
    public R<List<CommonVo>> getAnnualList() {
        return R.ok(taskServiceImpl.getAnnualList());
    }

    //任务列表(树形)
    @GetMapping("/taskListTreePart")
    @Operation(summary = "4.任务列表(树形)")
    public R<List<TaskTreePartVo>> taskListTreePart(@Schema(description = "学院ID")
                                                    @RequestParam(value = "organizeId", required = false) Long organizeId,
                                                    @Schema(description = "年度(yyyy-MM)")
                                                    @RequestParam(value = "annual", required = false) String annual,
                                                    @Schema(description = "是否为新增操作")
                                                    @RequestParam(value = "isAdd", required = false) Boolean isAdd) {
        return R.ok(taskServiceImpl.taskListTreePart(organizeId, annual,isAdd));
    }

//    //任务列表(树形)(目录)
//    @GetMapping("/taskListTreePartOne")
//    @Operation(summary = "5.任务列表(目录)",hidden = true)
//    public R<List<TaskTreePartOneVo>> taskListTreePartOne(@Schema(description = "学院ID")
//                                                          @RequestParam(value = "organizeId", required = false) Long organizeId) {
//        return R.ok(taskServiceImpl.taskListTreePartOne(organizeId));
//    }
//
//    @PutMapping("/updateListTreePartOne")
//    @Operation(summary = "5.任务列表(目录)-修改",hidden = true)
//    public R<Boolean> updateListTreePartOne(@RequestBody TaskPartUpdateDto dto) {
//        return R.ok(taskServiceImpl.updateListTreePartOne(dto));
//    }
//
//    @PostMapping("/addListTreePartOne")
//    @Operation(summary = "5.任务列表(目录)-添加",hidden = true)
//    public R<Boolean> addListTreePartOne(@RequestBody TaskPartAddDto dto) {
//        return R.ok(taskServiceImpl.addListTreePartOne(dto));
//    }

    //任务预算信息
    @GetMapping("/getTaskBudget")
    @Operation(summary = "5.任务预算和决算信息")
    public R<TaskBudgetAndFinalAccountVo> getTaskBudget(@Schema(description = "任务ID")
                                                        @RequestParam("id") Long id) {
        return R.ok(taskServiceImpl.getTaskBudget(id));
    }


    //修改任务决算信息
    @PostMapping("/addFinalAccount")
    @Operation(summary = "6.添加任务决算信息(上传凭证)")
    public R<Boolean> addFinalAccount(@RequestBody TaskFinalAccountDto dto) {
        return R.ok(taskServiceImpl.addFinalAccount(dto));
    }


    @PutMapping("/updateFinalAccount")
    @Operation(summary = "7.修改任务决算信息(上传凭证)")
    public R<Boolean> updateFinalAccount(@RequestBody TaskFinalAccountDto dto) {
        return R.ok(taskServiceImpl.updateFinalAccount(dto));
    }

//    //上传凭证
//    @PostMapping("/addFinalAccountFile")
//    @Operation(summary = "9.添加任务决算信息(上传凭证)")
//    public R<Boolean> addFinalAccountFile(@RequestBody TaskFinalAccountFileDto dto) {
//        return R.ok(taskServiceImpl.addFinalAccountFile(dto));
//    }
//
//    //任务成果列表
//    @GetMapping("/getTaskAchieveList")
//    @Operation(summary = "8.成果列表",hidden = true)
//    public R<List<CommonVo>> getTaskAchieveList(@Schema(description = "任务ID")
//                                                @RequestParam("id") Long id) {
//        return R.ok(taskServiceImpl.getTaskAchieveList(id));
//    }

    @GetMapping("/getTaskAchieveDetails")
    @Operation(summary = "9.成果详情")
    public R<TaskAchieveDetailsVo> getTaskAchieveDetails(@Schema(description = "成果ID")
                                                         @RequestParam("taskAchieveId") Long taskAchieveId) {
        return R.ok(taskServiceImpl.getTaskAchieveDetails(taskAchieveId));
    }


    @PostMapping("/saveTaskAchieve")
    @Operation(summary = "10.添加成果")
    public R<Boolean> saveTaskAchieve(@RequestBody TaskAchieveDetailsDto dto) {
        return R.ok(taskServiceImpl.saveTaskAchieve(dto));
    }


    @PutMapping("/updateTaskAchieve")
    @Operation(summary = "11.修改成果")
    public R<Boolean> updateTaskAchieve(@RequestBody TaskAchieveDetailsDto dto) {
        return R.ok(taskServiceImpl.updateTaskAchieve(dto));
    }

    @DeleteMapping("/deleteTaskAchieve")
    @Operation(summary = "12.删除成果")
    public R<Boolean> deleteTaskAchieve(@Schema(description = "成果ID")
                                        @RequestParam("taskAchieveId") Long taskAchieveId) {
        return R.ok(taskServiceImpl.deleteTaskAchieve(taskAchieveId));
    }


    @GetMapping("/getTaskDetails")
    @Operation(summary = "13.任务详情")
    public R<TaskDetailsVo> getTaskDetails(@Schema(description = "任务ID")
                                           @RequestParam("id") Long id) {
        return R.ok(taskServiceImpl.getTaskDetails(id));
    }


    //筛选项==========================================================================================================
    //===============================================================================================================
    @GetMapping("/getTaskList")
    @Operation(summary = "建设进度任务列表(筛选项)")
    public R<List<CommonVo>> getTaskList(@Schema(description = "任务名称")
                                         @RequestParam(value = "name", required = false) String name) {
        return R.ok(taskServiceImpl.getTaskListOne(name));
    }


    @GetMapping("/getCollegeList")
    @Operation(summary = "学院列表(筛选项)")
    public R<List<CommonVo>> getCollegeList(@Schema(description = "学院名称")
                                            @RequestParam(value = "name", required = false) String name) {
        return R.ok(organizeServiceImpl.getCollegeList(name));
    }

    //负责人筛选项
    @GetMapping("/getUserList")
    @Operation(summary = "负责人(参与者)(筛选项)")
    public R<List<OrganizeMemberPartVo>> getUserList(@Schema(description = "人员姓名")
                                                     @RequestParam(value = "realName", required = false) String realName) {
        return R.ok(userServiceImpl.getUserList(realName));
    }


}
